<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="../css/mystyle.css" />
<title>QUẢN LÝ BÀI VIẾT</title>
</head>
<?php 
    session_start();
?>
<body class="pagebody">
<?php
    include 'Article_model.php';
    if(isset($_GET['ID_show']))
    {
        $ID=$_GET['ID_show'];
         $article= getArticle($ID);     
        foreach ($article as $a) {
           echo '<div class="image-article"><img src="'.$a[3].'" width="150px" height="150px"></div>';            
           echo '<div class="title-article">'.$a[0].'</div>';
            echo  '<div class="content-article">'.$a[1].'</div>';
        }
//       
    }
    if(isset($_POST['submit'])&& $_POST['submit']=='Đăng bài')
    {
        $now = getdate();
        $currentTime = $now["hours"] . ":" . $now["minutes"] . ":" . $now["seconds"];
        $currentDate =   $now["year"]. "-" . $now["mon"] . "-" .$now["mday"] ;
        $title= $_POST['txtTitle'];
        $content=$_POST['txtContent'];
        $author=$_POST['txtAuthor'];
        $nameimg=$_FILES['img']['name'];
        $url="../upload/".$_FILES['img']['name'];
        $UserName=$_SESSION['user'][1];
       // echo $currentTime;
        if($title!=NULL && $content!=NULL && $author!=NULL && $nameimg !=NULL)
        {
            $rs=  InsertArticle($title, $content, $author, $currentDate,$url,$UserName);
            if($rs==1)
            {
                move_uploaded_file($_FILES['img']['tmp_name'],"../upload/".$_FILES['img']['name']);
               echo '<div class="message">Đăng bài thành công</div>';
               header("refresh:1;url=v_showArticle.php");
            }
            else echo 'ERROR:NOT SUCCESSFUL';
        }
        else
        {
            echo'Nhập đủ thông tin<br>';
            echo '<a href="javascript:history.go(-1)">quay lai</a>';
        }
    }
    if(isset($_GET['ID_Article']))
    {
        $ID=$_GET['ID_Article'];
        $rs= DeleteArticle($ID);
        if($rs!=0)
        {
            echo '<div class="message"><font color="blue">Xoá thành công</font></div>';
             header("refresh:1;url=v_admArticle.php");
        }
        else
            echo 'Xoá không thành công';
    }
     if(isset($_POST['capnhat'])&& $_POST['capnhat']=='Cập nhật')
    {
         $now = getdate();
//        $currentTime = $now["hours"] . ":" . $now["minutes"] . ":" . $now["seconds"];
        $updateDate =   $now["year"]. "-" . $now["mon"] . "-" .$now["mday"];
        $ArticleID=$_POST['txtID'];
        $title= $_POST['txtTitle'];
        $content=$_POST['txtContent'];
        $author=$_POST['txtAuthor'];
        if($title!=NULL && $content!=NULL && $author!=NULL)
        {
            $rs=  UpdateArticle($title, $content, $author, $updateDate,$ArticleID);
            if($rs>0)
            {
                 echo '<div class="message"><font color="blue">Cập nhật thành công</font></div>';
                 header("refresh:1;url=v_showArticle.php");
            }
            else echo 'ERROR:NOT SUCCESSFUL';
        }
        else
            echo'Khong duoc de trong';
    }
    if(isset($_GET['ID_ArticleCheck']))
    {
        $idcheck=$_GET['ID_ArticleCheck'];
        $Allowable=1;
        $rs=  UpdateAllow($Allowable, $idcheck);
        if($rs!=0)
        {
             header("refresh:0;url=v_admArticle.php");
        }
        else
             echo '<div class="message"><font color="red">Thao tác không thành công</font></div>';
    }
    if(isset($_GET['ID_ArticleUncheck']))
    {
        $idcheck=$_GET['ID_ArticleUncheck'];
        $Allowable=0;
        $rs=  UpdateAllow($Allowable, $idcheck);
        if($rs!=0)
        {
             header("refresh:0;url=v_admArticle.php");
        }
        else
             echo '<div class="message"><font color="red">Thao tác không thành công</font></div>';
    }
?>
</body>
</html>